import git
import subprocess

import tkinter as tk
from tkinter import *
from tkinter import ttk

repo = git.Repo("../.git/")
commit = repo.commit()

def openGitPublishCommit():
    from Apps.Functions.PrepareAndPublishGitCommit import CheckMessageToCommit

    root = Tk()
    root.title("Unreal Project Developer Tools ( UPDT ) - Publish commit")
    root.geometry("300x400")
    root.resizable(False, False)

    frame = Frame(root, padx=10, pady=10)
    frame.pack(expand=True)
    
    CommitTip_label = ttk.Label(frame, text="Enter your commit message")
    CommitTip_label.grid(row=1, column=1)

    CommitMessage_Entry = ttk.Entry(frame, width=40)
    CommitMessage_Entry.grid(row=2, column=1)
    CommitMessage_Entry.focus()

    LatestCommit = commit.message
    LatestCommitAuthor = commit.author
    LatestCommitDateTime = commit.authored_datetime
    LatestCommit_label = ttk.Label(frame, text=f'Latest commit:\nAuthor:{LatestCommitAuthor}\nMessage:{LatestCommit}\nDate: {LatestCommitDateTime}')
    LatestCommit_label.grid(row=3, column=1)

    PublishCommit_Button = ttk.Button(frame, text="Publish", command=lambda:CheckMessageToCommit(CommitMessage_Entry.get()), width=40)
    PublishCommit_Button.grid(row=4, column=1)
